package com.hyzh.latte.vehicle.service;

import com.coffee.mybatis.CoffeeDynamicTableNameContextHolder;
import com.hyzh.latte.vehicle.dmo.VehicleTrackCameraVO;
import com.hyzh.latte.vehicle.dmo.VehicleVO;
import com.hyzh.latte.vehicle.dmo.entity.PersonTrackRecordPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.VehicleTrackRecordPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.VtypeEntity;
import com.hyzh.latte.vehicle.repository.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * @author songkui
 * @since 2024/3/20 17:13
 */
@Service
@Slf4j
@AllArgsConstructor
public class NezhaRecordService {

    private final VehicleTrackRecordPGRepository vehicleTrackRecordPGRepository;
    private final PersonTrackRecordPGRepository personTrackRecordPGRepository;
    private final VtypePGRepository vtypePGRepository;


    public void saveVehicle(String park, VehicleTrackRecordPGEntity trackRecordEntity) {
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        vehicleTrackRecordPGRepository.save(trackRecordEntity);
    }
    public void saveVType(String park, VtypeEntity vtypeEntity) {
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        vtypePGRepository.save(vtypeEntity);
    }

//    public void saveInout(String park, VehicleInoutRecordPGEntity recordPGEntity){
//        CoffeeDynamicTableNameContextHolder.setTableName(park);
//        vehicleInoutRecordPGRepository.save(recordPGEntity);
//    }

    public void savePerson(String park, PersonTrackRecordPGEntity trackRecordDTO) throws Exception {
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        personTrackRecordPGRepository.save(trackRecordDTO);
    }

    public void savePersonBatch(String park, Collection<PersonTrackRecordPGEntity> collection)throws Exception{
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        personTrackRecordPGRepository.saveBatch(collection);
    }

    public List<String> listVehicleNo(String park, String vno, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.listVehicleNo(vno, startTime, endTime);
    }


    public  List<VehicleTrackRecordPGEntity> listTrackRecord(String park, String vo, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.listTrackRecord(vo, startTime, endTime);
    }


    public  List<VehicleTrackRecordPGEntity> listVehicleTrack(String park, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.listVehicleTrack(startTime, endTime);
    }

    public  List<VehicleVO> listTrackVehicle(String park, String vo, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.listVehicleVO(vo, startTime, endTime);
    }
    public  List<VehicleVO> listTrackVehicleOnline(String park, String vo, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.listVehicleVOOnline(vo, startTime, endTime);
    }

    public List<VehicleTrackCameraVO> enterpriseCamera(String park, String cno, String vno, LocalDateTime startTime, LocalDateTime endTime){
        CoffeeDynamicTableNameContextHolder.setTableName(park);
        return vehicleTrackRecordPGRepository.enterpriseCamera(cno, vno, startTime, endTime);
    }



}
